package cn.gjxblog.scheduling.spring;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;

import java.util.concurrent.ScheduledThreadPoolExecutor;

@Configuration
@EnableScheduling
@ComponentScan("cn.gjxblog.scheduling.spring")
public class RootConfig implements SchedulingConfigurer {
    @Override
    public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
        //方法一
//        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
//        threadPoolTaskScheduler.setPoolSize(10);
//        threadPoolTaskScheduler.setThreadNamePrefix("myTask");
//        // 注意一点要调用
//        threadPoolTaskScheduler.initialize();
//        taskRegistrar.setTaskScheduler(threadPoolTaskScheduler);

        //方法二
        ScheduledThreadPoolExecutor scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(10);
        taskRegistrar.setScheduler(scheduledThreadPoolExecutor);

    }
}
